﻿using MySql.Data.MySqlClient;
using NB.MGJ.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;



namespace NB.MGJ.Service
{
    /// =======================================================================
    /// 类名：ProductService ProductService的备注：ProductService~1<br/>
    /// =======================================================================<br/>
    /// 更新履历<br/>
    /// 序号          更新日期          责任人           更新内容<br/>
    /// 001           2017年9月2日       段扬             新建<br/>
    /// =======================================================================<br/>
    
    public partial class ProductService
    {


//////////////////////////////此service所有方法都已转移到origing_templet和origins_node 确认无误后将删除///////////////////////
////////////////////////////////////////////////////////////产品模板//////////////////////////////////////////////////////////




        #region 增

        public int AddTemplet(Origins_Templet model)
        {
            return _baseRepository.Insert(model);
        }


        
        #endregion


        #region 删
        public int DelTemplet(int? productId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete Origins_Templet where TempletId=" + productId);
            return _baseRepository.ExecuteSql<int>(strSql.ToString());
        }

        #endregion

        #region 改

        public int UpdTemplet(Origins_Templet model)
        {
            return _baseRepository.Update(model);
        }

        #endregion


        #region 查

        public PagedList<Origins_Templet> GetTemplateList(ref PagerModel pager)
        {
            StringBuilder strSql1 = new StringBuilder();
            strSql1.Append("Origins_Templet.*,");
            strSql1.Append(" (select ProductName from Product_Product where Origins_Templet.TempletId=Product_Product.ID  ) as ProductName,");
            strSql1.Append(" (select ClassifyName from Product_Classify where Origins_Templet.ClassifyId=Product_Classify.ID  ) as ClassifyName ");
            pager.FldName = strSql1.ToString();
            pager.TblName = " Origins_Templet ";
            MySqlParameter[] parameters = _baseRepository.SqParameterRefactor(ref pager);
            IEnumerable<Origins_Templet> resultList = _baseRepository.ExecuteStoredProcedureCollection<Origins_Templet>("Common_PageList", parameters).ToList();
            return new PagedList<Origins_Templet>(resultList.ToList(), pager.Page, pager.PageSize, 1, Convert.ToInt32(parameters[6].Value));
        }

        #endregion



///////////////////////////////////////////////////////////节点//////////////////////////////////////////////////////////////
        /// <summary>
        /// 根据主键查询表数据
        /// </summary>
        /// <param name=" ButtonId">string 主键--查询条件</param>
        /// <returns>DataTable 查询结果集</returns>
        public Origins_Node GetNodeModel(int ID)
        {
            Origins_Node model = new Origins_Node();
            StringBuilder strSql = new StringBuilder();

            strSql.Append(" select ");
            strSql.Append("  ID,");
            strSql.Append("EnterpriseId ,");
            strSql.Append("FlowID ,");
            strSql.Append("NodeName ,");
            strSql.Append("NodeType,");
            strSql.Append("Category ,");
            strSql.Append("IsH5 ,");
            strSql.Append("Permission ,");
            strSql.Append("ViewDel ,");
            strSql.Append("Sequence ,");
            strSql.Append("ChangeLoginID ,");
            strSql.Append("ChangeLoginName ,");
            strSql.Append("ChangeDate ,");
            strSql.Append("NodeContent,");
            strSql.Append("ImgUrl,");
            strSql.Append("VideoUrl,");
            strSql.Append("EnterTimes,");
            strSql.Append("PermissionPerson,");
            strSql.Append("Display");
          
            strSql.Append(" from Origins_Node ");
            strSql.Append(" where  ID='" + ID + "'");

            MySqlParameter[] parameters = {
					new MySqlParameter("@ID",ID)
			};
 
            model = _baseRepository.ExecuteText<Origins_Node>(strSql.ToString(),parameters);
            return model;
        }

        /// <summary>
        ///  根据模板ID获取模板节点
        /// </summary>
        /// <param name="flowId">流程ID</param>
        /// <returns></returns>
        public List<Origins_Node> getTemletListByFlowId(int flowId,int nodeType)
        {
          string sql = " select * from (  SELECT  * from Origins_Node where FlowID=" + flowId + " and NodeType="+nodeType+" and  Origins_Node.ViewDel=0 ) Node";
            var result = _baseRepository.ExecuteSqlCollection<Origins_Node>(sql).ToList();
            return result;
        }
        /// <summary>
        ///物理删除  产品模板
        /// </summary>
        /// <returns></returns>


    }
}
